package com.ncloud.crm.mapper;

import java.util.List;

import org.apache.ibatis.annotations.*;

import com.ncloud.crm.entity.BsNodeAttr;
@Mapper
public interface BsNodeAttrMapper {

	@Insert("insert into bs_node_item(node_id, attr_id, attr_type, attr_code, attr_value, begin_date, end_date)"
			+ " values(#{nodeId}, #{attrId}, #{attrType}, #{attrCode}, #{attrValue}, #{beginDate}, #{endDate})")
	int insertNodeAttr(BsNodeAttr attr);

	@Update("update bs_node_item set attr_value=#{attrValue}, end_date=#{endDate} where attr_id=#{attrId}")
	int updateNodeAttr(BsNodeAttr attr);

	@Select(value = { "select * from bs_node_item where 1=1 and node_id = #{nodeId} and attr_type=#{attrType}" +
			" and attr_code=#{attrCode} and begin_date <=  #{beginDate} and end_date >=#{endDate}" })
	@Results({ @Result(column = "node_id", property = "nodeId"), @Result(column = "attr_id", property = "attrId"),
			@Result(column = "attr_type", property = "attrType"),@Result(column = "attr_value", property = "attrValue"),
			@Result(column = "attr_code", property = "attrCode"),@Result(column = "end_date", property = "endDate"),
			@Result(column="begin_date",property="beginDate")})
	public BsNodeAttr getNodeEqptInfo(BsNodeAttr bsNodeAttr);

	@Select(value = { "select * from bs_node_item where node_id = #{nodeId} and now() between begin_date and end_date " })
@Results({ @Result(column = "node_id", property = "nodeId"), @Result(column = "attr_id", property = "attrId"),
		@Result(column = "attr_type", property = "attrType"),@Result(column = "attr_value", property = "attrValue"),
		@Result(column = "attr_code", property = "attrCode"),@Result(column = "end_date", property = "endDate"),
		@Result(column="begin_date",property="beginDate")})
	List<BsNodeAttr> getNodeAttrs(Long nodeId);
	
	@Select(value = { "select * from bs_o_work_node_attr where node_id = #{nodeId} and now() between begin_date and end_date " })
	@Results({ @Result(column = "node_id", property = "nodeId"), @Result(column = "attr_id", property = "attrId"),
			@Result(column = "attr_type", property = "attrType"),@Result(column = "attr_value", property = "attrValue"),
			@Result(column = "attr_code", property = "attrCode"),@Result(column = "end_date", property = "endDate"),
			@Result(column = "work_id", property = "workId"),@Result(column = "modify_tag", property = "modifyTag"),
			@Result(column="begin_date",property="beginDate")})
	List<BsNodeAttr> getBsNodeAttrs(Long nodeId);

	@Select(value = { "select * from bs_node_item where 1=1 and node_id = #{nodeId} and attr_type=#{attrType}" +
			" and attr_code=#{attrCode} and now() between begin_date and end_date" })
	@Results({ @Result(column = "node_id", property = "nodeId"), @Result(column = "attr_id", property = "attrId"),
			@Result(column = "attr_type", property = "attrType"),@Result(column = "attr_value", property = "attrValue"),
			@Result(column = "attr_code", property = "attrCode"),@Result(column = "end_date", property = "endDate"),
			@Result(column="begin_date",property="beginDate")})
	public BsNodeAttr getNodeAttrByPk(BsNodeAttr bsNodeAttr);

}
